package jmovie;
import java.awt.BorderLayout;
import javax.swing.BorderFactory;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
import javax.swing.WindowConstants;

public class WaitDialog extends JDialog {
	private static final long serialVersionUID = 1L;
	JPanel jPanel1;
	JLabel waitLabel;
	String message;
	
	static JProgressBar progressBar;

	boolean complete = false;
	static boolean decrement = false;
	
	public WaitDialog(String message) {
		super(GuiManager.getFrame());
		this.message = message;
	}
	
	public void start() {
		Thread t1 = new Thread(new Runnable() {
			@Override
			public void run() {
				initGUI();
				progressBar.setIndeterminate(true);
				while (!complete) {
					try {
						Thread.sleep(10);
					} catch (Exception e) {
					}
				}
				dispose();
			}
		});
		t1.start();
	}
	
	private void initGUI() {
		this.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
		progressBar = new JProgressBar();
		waitLabel = new JLabel();
		waitLabel.setText(message);
		waitLabel.setFont(new java.awt.Font("Tahoma", 1, 12));
		waitLabel.setBorder(BorderFactory.createEmptyBorder(20, 40, 20, 40));
		
		add(waitLabel, BorderLayout.NORTH);
		JPanel p = new JPanel();
		p.setBorder(BorderFactory.createEmptyBorder(10, 10, 20, 10));
		add(p,BorderLayout.SOUTH);
		p.add(progressBar, BorderLayout.SOUTH);
		
		pack();
		setLocationRelativeTo(GuiManager.getFrame());
		setVisible(true);
	}
	
	public void setComplete(boolean complete) {
		this.complete = complete;
	}
}
